#!/usr/bin/env python
# -*- coding: utf-8 -*-

# @Time     :2022/03/02
# @Author   :Changshu
# @File     :Exercise5.py
# 5. 最长回文子串

def longestPalindrome(s: str) -> str:
	maxi,maxj=0,0
	dp=[[True]*len(s) for _ in range(len(s))]
	i,j=0,1
	while j<len(s):
		if s[i]==s[j]:
			if i==j-1:
				dp[i][j]=True
			else:
				dp[i][j]=dp[i+1][j-1]
		else:
			dp[i][j]=False
		if dp[i][j] and (j-i)>(maxj-maxi):
			maxi,maxj=i,j
		if i==j-1:
			i=0
			j+=1
		else:
			i+=1
	return s[maxi:maxj+1]

if __name__ == '__main__':
	# l=[1,2,3,4,5,6]
	# print(l)
	# print(l.pop())
	# print(l)
	# s='abcde'
	# print(s[0])
	# print('a'=='a')
	# r=['a','b','c','d','e']
	# print(str(r))
	# print(''.join(r))
	# print(['a']*4)
	# print(list(s))
	# print([]*4)
	# res = ['' for _ in range(4)]
	# print(res)
	# a=['12345','678','9']
	# print(''.join(a))

	# print([['a'])
	# num_list1=[[0]*5 for _ in range(4)]
	# num_list2=[[0]*5]*4
	# print(num_list1)
	# print(num_list2)
	# s='abcdef'
	# print(s[0:1])

	s='cbbd'
	print(longestPalindrome(s))
	# print(s[0:1])